package com.wonders.frame.repository;

import com.wonders.frame.entity.AuthRolePermission;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

@Repository
public interface AuthRolePermissionRepository extends JpaRepository<AuthRolePermission, String>, JpaSpecificationExecutor<AuthRolePermission> {

    List<AuthRolePermission> findByRoleId(String roleId);

    @Transactional
    void deleteByRoleId(String roleId);

    @Transactional
    void deleteByPermissionId(String permissionId);

    @Query("select a.permissionId from AuthRolePermission a where a.roleId=?1")
    List<String> findPermissionIdByRoleId(String roleId);
}
